package zdsoft.nbfsc.task;

import java.util.UUID;
import sense.vitality.ioc.SenseInjection;
import sense.vitality.lifetime.SenseContext;
import sense.vitality.protocol.Stuff;
import sense.vitality.security.RestrictionAnalyst;
import sense.vitality.security.entity.Actor;

import sense.vitality.task.SecuredTask;


import sense.vitality.text.Result;
import sense.vitality.utility.Password;
import sense.vitality.verify.Parameter;
import sense.vitality.verify.Verify;
import sense.vitality.verify.VerifyCategory;

/**
 *
 * @author elegance
 */
public class CreateActorTask extends SecuredTask {

    @SenseInjection
    private SenseContext senseContext;

    @Override
    protected Stuff execute(Stuff request, RestrictionAnalyst restrictionAnalyst) {
        Param param = request.getParameter();
        Actor actor = new Actor();
        actor.setAllowLogins(param.getAllowLogins());
        actor.setEmail(param.getEmail());
        actor.setIdent(param.getIdent());
        actor.setName(param.getName());
        actor.setMobileNumber(param.getMobileNumber());
        actor.setId(UUID.randomUUID().toString());
        actor.setPassword(Password.getDigest(param.getPassword()));
        Result result = senseContext.getStorageActuator().insertObject(actor);
        return request.instanceResponse(result);
    }

    public static class Param extends Parameter {

        @Verify
        private String name;
        @Verify
        private String password;
        @Verify(VerifyCategory.PICK)
        private String ident;
        @Verify(VerifyCategory.PICK)
        private String email;
        @Verify(VerifyCategory.PICK)
        private String mobileNumber;
        private int allowLogins;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }

        public String getIdent() {
            return ident;
        }

        public void setIdent(String ident) {
            this.ident = ident;
        }

        public String getEmail() {
            return email;
        }

        public void setEmail(String email) {
            this.email = email;
        }

        public String getMobileNumber() {
            return mobileNumber;
        }

        public void setMobileNumber(String mobileNumber) {
            this.mobileNumber = mobileNumber;
        }

        public int getAllowLogins() {
            return allowLogins;
        }

        public void setAllowLogins(int allowLogins) {
            this.allowLogins = allowLogins;
        }
    }

}
